//
// Created by richa on 2019/11/16.
//

#ifndef GREENHOUSEMA_SIMPLC_H
#define GREENHOUSEMA_SIMPLC_H

#include "../modbus/modbus.h"
#include <thread>
#include <mutex>
#include <condition_variable>

namespace Sim{
    class SimPlc {
    public:
        explicit SimPlc(void (*function1)(), void(*init)(unsigned short * D));

    private:
        modbus_mapping_t *mb_mapping;
        std::thread timerThread;
        std::thread plcThread;

        unsigned char * M_p;
        unsigned char * X_p;
        unsigned char * Y_p;
        unsigned short * D_p;

        void initMemery(void (*init)(unsigned short * D));
    public:
        modbus_mapping_t *getMbMapping() const;
        std::mutex * mutex = new std::mutex();
        std::condition_variable cv;
        bool initFlag = false;

        unsigned char * getM_Addr(){return M_p;}
        unsigned char * getX_Addr(){return X_p;}
        unsigned char * getY_Addr(){return Y_p;}
        unsigned short * getD_Addr(){return D_p;}
    };

}



#endif //GREENHOUSEMA_SIMPLC_H
